home *** CD-ROM | disk | FTP | other *** search
/ Practical Algorithms for Image Analysis / Practical Algorithms for Image Analysis.iso / CH_6.3 / XSGT / VORA.H < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-11  |  8.1 KB  |  233 lines

  1. /*
  2.  * VOR(oronoi)A(nalysis).H
  3.  *
  4.  */
  5.  
  6. #ifndef _VORA_H_
  7. #define _VORA_H_
  8.  
  9. #include "ip.h"
  10.  
  11. #define    SIGN(a)        ( ((a) == 0.0) ? 0 : ( ((a) < 0.0) ? -1 : 1 ) )
  12. #define    F_TO_INT(x)    ( ((x)-(int)(x)<0.5) ? (int)(x) : (int)(x)+1 )
  13.  
  14. /* define display AOI */
  15. #define    ULX        0
  16. #define    ULY        0
  17. #define    LRX        511
  18. #define    LRY        479
  19.  
  20.  
  21. /* define ``active'' AOI, excluding edge of display AOI */
  22. #define    AULX        64
  23. #define    AULY        64
  24. #define    ALRX        LRX-64
  25. /*#define       ALRY            LRY-64 */
  26. #define    ALRY        LRY-112           /* employ when parm displ in video inp */
  27.  
  28.  
  29. struct Pix {
  30.   float x;
  31.   float y;
  32. };
  33.  
  34.  
  35. struct Tuple {
  36.   float x;
  37.   float y;
  38.   int index;
  39. };
  40.  
  41.  
  42. /* structure used both for sites and for vertices */
  43. struct vSite {
  44.   struct Pix coord;
  45.   int sitenbr;
  46.  
  47.   int nnn;                      /* coordination number */
  48.   float *nnd;                   /* array of nn distances */
  49.   int *nnsi;                    /* array contain ind of nn sites */
  50.   unsigned int area;            /* area of bubble domain occup site */
  51.   unsigned int v_area;          /* area of Vor poly, obt from vPoly */
  52.  
  53.   Boolean eFlag;                /* mark site near AOI edge */
  54.   Boolean aoiFlag;              /* mark site out-of-bounds */
  55.   /* 0: UnSet, 1: Set */
  56.  
  57.   Boolean status;               /* status (0: InActive, 1: Active) */
  58.   /* employed in kNN construction */
  59. };
  60.  
  61.  
  62.  
  63. struct vEdge {
  64.   int edgenbr;
  65.   int vO, vF;                   /* indices of V. vertices delimiting edge */
  66.   int sO, sF;                   /* indices of sites delimiting edge bisector */
  67. };
  68.  
  69.  
  70. struct vPoly {
  71.   struct Pix coord;
  72.   int sitenbr;                  /* Voronoi site interior to poly */
  73.  
  74.   int ne;                       /* number of poly edges ( == nof NN) */
  75.   int *pei;                     /* index array of V. poly edges */
  76.   float *vel;                   /* array of V. edge lengths */
  77.  
  78.   float *sphi;                  /* array of sin(a), angle a subt by V. edge */
  79.  
  80.   int *pvi;                     /* index array of poly vertices */
  81.   float area;
  82.  
  83.   Boolean aoiFlag;              /* mark poly if assoc site out-of-bounds */
  84.   Boolean eFlag;                /* mark poly if edge crosses AOI bounds */
  85.   Boolean lFlag;                /* mark polygon with ``vanishing'' edge len */
  86. };
  87.  
  88.  
  89. struct oHisto {
  90.   int nh, nb;                   /* no input data, no histogram bins */
  91.   float *phd;                   /* ptr to array of input data */
  92.   float *ph;                    /* ptr to array of histogram data */
  93.   float bw;                     /* bin width */
  94.   float amin, amax;
  95.   double mean, std_dev;
  96. };
  97.  
  98.  
  99. struct nnSite {
  100. /*      struct Pix coord; */
  101.   int sitenbr;
  102.  
  103.   Boolean status;               /* status: InActive, Active */
  104. };
  105.  
  106. struct kNNShell {
  107.   int sitenbr;                  /* Site index */
  108.   int kNN;                      /* nof NN shells (lists) constr for given Site */
  109.   double frms;                  /* fractal measure, eval for given shell */
  110.  
  111.   double *aka;                  /* array of avrg areas of kNN domains */
  112.  
  113.   int tc;                       /* topol charge, c = n-6 */
  114.   double *tctc;                 /* array of products, c(0)c(k)/nkNN */
  115.  
  116.   /*      struct linklist *sha; *//* array of lists, repr k-NN shells */
  117.   /* would be relevant for array vers */
  118. };
  119.  
  120.  
  121.  
  122.  
  123. /* function prototypes */
  124. /* xvora.c */
  125. extern void exitmess (char *prompt, int status);
  126. extern void fail_alloc (char *prompt, int status);
  127. #if defined(LINUX)
  128. extern int sycomp (struct vSite *s1, struct vSite *s2);
  129. #else
  130. extern int sycomp (const void *s1, const void *s2);
  131. #endif
  132. #if defined(LINUX)
  133. extern int sxcomp (struct vSite *s1, struct vSite *s2);
  134. extern int compare (float *t1, float *t2);
  135. #else
  136. extern int sxcomp (const void *s1, const void *s2);
  137. extern int compare (const void *t1, const void *t2);
  138. #endif
  139. extern void gprintf (FILE * fpOut, char *fmt,...);
  140. extern void main (int argc, char **argv);
  141. /* getopt.c */
  142. static void get_next_index (void);
  143. extern int getopt (int argc, char **argv, char *optstring);
  144. /* vora.c */
  145. extern struct Tuple *edge_mp (struct vSite *v1, struct vSite *v2, int index);
  146. #if defined(LINUX)
  147. extern int winding_ccwT (struct Tuple *r1, struct Tuple *r2);
  148. #else
  149. extern int winding_ccwT (const void *r1, const void *r2);
  150. #endif
  151. extern void sort_poly_edges (struct Tuple *pem,
  152.                              struct vSite *s, struct vPoly *p);
  153. #if defined(LINUX)
  154. extern int esO_comp (struct vEdge *e1, struct vEdge *e2);
  155. #else
  156. extern int esO_comp (const void *e1, const void *e2);
  157. #endif
  158. #if defined(LINUX)
  159. extern int esF_comp (struct vEdge *e1, struct vEdge *e2);
  160. #else
  161. extern int esF_comp (const void *e1, const void *e2);
  162. #endif
  163. extern double slen (struct vSite *v1, struct vSite *v2);
  164. extern int site_geom (struct vSite *s, struct vSite *v,
  165.                       struct vEdge *e, struct vPoly *p, int ns, int ne);
  166. #if defined(LINUX)
  167. extern int e_comp (struct vEdge *e1, struct vEdge *e2);
  168. #else
  169. extern int e_comp (const void *e1, const void *e2);
  170. #endif
  171. extern double T_area (struct vSite *v1, struct vSite *v2, struct vSite *v3);
  172. extern Boolean check_e (int e_vO, int e_vF);
  173. extern int *pe_dist (struct vPoly *p, int ns, int nel, int neu);
  174. extern void poly_geom (struct vSite *s, struct vSite *v, struct vEdge *e,
  175.                struct vPoly *p, struct Tuple *pem, int ns, int ne, int CPV);
  176. extern void mark_eSites (struct vSite *s, int ns);
  177. extern void mark_eEdges (struct vSite *s, struct vEdge *e, int ne);
  178. extern Boolean check_s (struct vSite *s);
  179. extern int *count_defects (struct vSite *s, int ns, int ncl, int ncu);
  180. extern Boolean check_v (struct vSite *v);
  181. extern void site_coordination (struct vSite *s, struct vSite *v,
  182.                                struct vEdge *e, int ns, int ne);
  183. extern double p_of_nVA (int *ndn, unsigned int **a_n, int ns, struct vPoly *p);
  184.  
  185. /* hist.c */
  186. extern double find_mean (float *data, int n);
  187. extern double find_sigma (float *data, int n, double mean);
  188. extern void construct_hist (int n, float *data, float *hist,
  189.                             double bw, double data_base);
  190. extern void construct_shist (int n, float *data, float *hist,
  191.                              double bw, double data_base);
  192. /* ds.c */
  193. extern double a_union (double rd, struct vSite *s, int ns);
  194. extern void eval_p (struct vSite *s,
  195.                  int ns, struct Tuple *pf, int npf, double r0, double area);
  196. extern void eval_q (float *hist, struct Tuple *qf, int nqf, double r0);
  197. /* knns.c */
  198. extern float eval_mn (struct vSite *vS, struct vSite *vsa);
  199. extern int m_of_n (int *idn, float **m_n, int ns, struct vSite *vsa);
  200. extern void eval_aka (struct vSite *vsa, int kNN, double *aka,
  201.                       struct linklist *sha);
  202. extern int eval_tctc (struct vSite *vsa, int kNN, double *tctc,
  203.                       struct linklist *sha);
  204. extern double eval_frms (int kNN, struct linklist *sha);
  205. extern int cmpSiteInd (struct nnSite *oldSite, struct nnSite *newSite);
  206. extern void init_sk (struct linklist *knnsll);
  207. extern Boolean scanSiteInd (struct nnSite *newSite, struct linklist *list);
  208. extern void expand_kNN_list (struct nnSite *nnnS, struct linklist *list);
  209. extern void contract_kNN_list (struct linklist *list);
  210. extern void show_kNN_list (struct linklist *list, int k);
  211. extern double xak_kNN_list (struct vSite *vsa, struct linklist *list, int k);
  212. extern double xck_kNN_list (struct vSite *vsa, struct linklist *list, int k);
  213. extern double xc0 (struct vSite *vsa, struct linklist *list);
  214. extern void init_sk0 (struct vSite *vsa, int sitenbr, struct linklist *list);
  215. extern void SetActive (struct vSite *vsa, int ns);
  216. extern struct linklist *kNNs (struct vSite *vsa, struct linklist *plist,
  217.                               struct linklist *clist, int k);
  218. extern double construct_kNNs (int ns, struct vSite *vsa,
  219.                               struct linklist *sha, struct kNNShell *sk);
  220. #if 0
  221. /* in vora_io.c */
  222. extern void write_hdt_data (FILE * fpOut, int n_parms, float *foo,
  223.                             struct Histo *h, struct Tuple *ds, int nd);
  224. extern void log_st_data (FILE * fpOut, char *wbuf, int ns,
  225.                          struct vSite *s);
  226. extern void log_pt_data (FILE * fpOut, char *wbuf, int ns,
  227.                 struct vPoly *p, struct vEdge *e, struct vSite *v, int CPV);
  228. extern void dump_poly_vc (FILE * fpOut, int ns, struct vPoly *p,
  229.                           struct vSite *v);
  230. #endif
  231.  
  232. #endif /* _VORA_H_ */
  233.